package com.photographysharing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.photographysharing.entity.Categories;
import com.photographysharing.request.SelectByPaging;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.service.CategoriesService;
import com.photographysharing.mapper.CategoriesMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Z
* @description 针对表【categories】的数据库操作Service实现
* @createDate 2024-05-14 21:15:11
*/
@Service
public class CategoriesServiceImpl extends ServiceImpl<CategoriesMapper, Categories>
    implements CategoriesService{

    private CategoriesMapper categoriesMapper;

    public CategoriesServiceImpl(CategoriesMapper categoriesMapper) {
        this.categoriesMapper = categoriesMapper;
    }

    @Override
    public DatasResponse<Categories> selectByPag(SelectByPaging pag) {
        int index = pag.getIndex();
        int size = pag.getSize();
        String name = pag.getSearchName();
        IPage<Categories> page = new Page<>(index,size);
        QueryWrapper<Categories> qw = new QueryWrapper<>();
        if(name != null && name !=""){
            qw.like("name",name);
        }
        IPage<Categories> pages = categoriesMapper.selectPage(page,qw);
        return new DatasResponse<Categories>((int)pages.getTotal(),pages.getRecords());
    }
}




